// pages/print/paySuccess/paySuccess.js
var utils = require("../../../utils/utils.js");
const app = getApp()
Page({
  data: {
    titleTop: app.globalData.navTop,
    titleHeight: app.globalData.menuButtonHeight,
    order: ''
  },
  wxContant(e) {
    var that = this;
    var url = e.currentTarget.dataset.url;
    var id = e.currentTarget.dataset.id;
    wx.openCustomerServiceChat({
      extInfo: { url: url },
      corpId: id,
      showMessageCard: true,
      sendMessageTitle: '打印订单详情',
      sendMessagePath: '/pages/my/orderDetail/orderDetail.html?id=' + that.data.order,
      success(res) {

      }
    })
  },
  goExchange() {
    wx.navigateTo({
      url: '/subPackages/pages/pointsMall/pointsMall',
    })
  },
  goToLink(e) {
    var url = e.currentTarget.dataset.link;
    var content = e.currentTarget.dataset.content;
    var id = e.currentTarget.dataset.id;
    var title = e.currentTarget.dataset.title;
    if (utils.is_define(url)) {
      if (url.indexOf('pages') != -1 && url.indexOf('mjyy') == -1) {
        wx.navigateTo({
          url: url,
        })
        return false;
      }
      if (url.indexOf('pages') != -1 && url.indexOf('mjyy') != -1) {
        wx.navigateToMiniProgram({
          appId: 'wxd8a7d886dc3c37d5',
          path: url,
          envVersion: 'release',
          success(res) {
            // 打开成功
          }
        })
        return false;
      }
      if (url.indexOf('https') != -1) {
        wx.navigateTo({
          url: '../my/agreement/agreement?url=' + url
        })
        return false;
      }
      if (content) {
        //信息详情
        wx.navigateTo({
          url: '/pages/my/pictureAdv/pictureAdv?id=' + id + '&name=' + title
        })
      }
    }
  },
  getBackInfo() {
    var that = this;
    utils.request('printOrder/paySuccess/' + that.data.order, {}, function (res) {
      wx.hideLoading()
      if (res.data.code == 200) {
        that.setData({
          time: res.data.data.time,
          couponsQrCode: res.data.data.qrCode,
          couponsQrText: res.data.data.qrCodeText,
          adv: res.data.data.scrollAdList,
          trip: res.data.data.tipsTitle,
          tel: res.data.data.serviceTel,
          customServiceId: res.data.data.wxServiceOpenId,
          customServiceUrl: res.data.data.wxServiceUrl,
          score: res.data.data.points
        })
        if (that.data.type != 'wk') {
          var data = wx.getLaunchOptionsSync()//获取场景代码
          // if (data.scene == 1047 || data.scene == 1011 || data.scene == 1025 || data.scene == 1124){
          //     that.getRedpack();
          // }
        }
      } else {

      }
    })
  },
  //   红包接口
  getRedpack() {
    var that = this;
    utils.request('member/getRed', {
      orderNo: that.data.order,
      door: 1,
      isLoad: -1,
    }, function (res) {
      if (res.data.code == 1) {
        wx.sendBizRedPacket({
          timeStamp: res.data.data.payInfo.timeStamp,
          nonceStr: res.data.data.payInfo.nonceStr,
          package: res.data.data.payInfo.package,
          signType: res.data.data.payInfo.signType,
          paySign: res.data.data.payInfo.paySign
        })
      }
    })
  },
  goAdvLink(e) {
    var url = e.currentTarget.dataset.url;
    if (utils.is_define(url)) {
      if (url.indexOf('pages') != -1) {
        wx.navigateTo({
          url: url,
        })
      }
      if (url.indexOf('https') != -1) {
        wx.navigateTo({
          url: '../my/agreement/agreement?url=' + url
        })
      }
    }
  },
  goHome() {
    wx.switchTab({
      url: '../../index/index',
    })
  },
  goRecord() {
    wx.redirectTo({
      url: '../../my/printOut/printOut',
    })
  },
  gowk() {
    wx.redirectTo({
      url: '../../my/wdwk/wdwk',
    })
  },
  callPhone() {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.tel //仅为示例，并非真实的电话号码
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      type: options.type,
      order: options.orderNo,
      printType: options.printType || ''
    })
    if (options.type != 'wk') {
      this.getBackInfo()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  callkf() {
    wx.makePhoneCall({
      phoneNumber: '4000921588',
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})